function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}


let destroy = (message) => {
  return (target, name, descriptor) => {
    // 参数类似于
    // Object.defineProperty(Class.prototype, 'name', descriptor);
    // descriptor对象原来的值如下
    // {
    //   value: specifiedFunction,
    //   enumerable: false,
    //   configurable: true,
    //   writable: true
    // };

    let method = descriptor.value;
    console.log(`message:${message},target:${target},name:${name},descriptor:${descriptor},`, target.name, name, descriptor.value,);
    descriptor.value = function (...args) {
      try {
        var result = method.apply(this, args); //result为被装饰函数的返回值
        console.log(`${message} 成功`)
      } catch (error) {
      }
      return result;
    }
  }
}

let testTime = () => {
  return (target, name, descriptor) => {
    let method = descriptor.value;
    descriptor.value = function (...args) {
      console.time("测试时间");
      var result = method.apply(this, args); //result为被装饰函数的返回值
      console.timeEnd("测试时间");
      return result;
    }
  }
}

let https = (path, requestMothod) => {
  return (target, name, descriptor) => {
    let method = descriptor.value;
    descriptor.value = function (...args) {
      // let obj = Object.create(target.prototype)
      // var result = method.apply(obj, args)
      var result = method.apply(this, args)
      // for (let i = 0; i < 30000; i++) {
      //   console.log(1, "打印输出")
      // }
      // await sleep(2000)
      console.log(`${name}`, `正在请求http://${path}`, requestMothod, result);
      return {
        data: { list: [] },
        resultCode: 200,
      }
    }
  }
}

export { destroy, testTime, https, sleep }